package cn.gson.springboot.model.service;

import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.springboot.model.dao.FactoryYkDAO;
import cn.gson.springboot.model.mapper.FactoryYkMapper;
import cn.gson.springboot.model.pojos.FactoryYk;

@Service
@Transactional(rollbackFor=Exception.class)
public class FactoryYkService {
	@Autowired
	private FactoryYkDAO a;
	@Autowired
	private FactoryYkMapper fm;
	
	//查询所有 
	public List<FactoryYk> findAll(){
		return fm.findAll();
	}
	
	//新增
	public void xinzeng(FactoryYk d) {
		 a.save(d);
	}
	
	//修改
	public void update(Integer factory_id,String factory_name,String factory_phone,String factory_people) {
		FactoryYk f = a.findById(factory_id).get();
		f.setFactoryName(factory_name);
		f.setFactoryPeople(factory_people);
		f.setFactoryPhone(factory_people);
		a.save(f);
	}
	
	//查询id
	public FactoryYk findbyid(Integer factoryId) {
		FactoryYk findbyid=a.findbyid(factoryId);
		return findbyid;
	}
	
	//根据供应商名称查询药品
	public JSONArray findgysyp(String factory_name){
		if(factory_name!=null) {
			if(factory_name.trim().equals("")) {
				factory_name=null;
			}
		}
		return fm.findgysyp(factory_name);
	}
}
